package design.pattern.Lu06ProxyPattern;

/**
 * @program day01
 * @description: 静态代理
 * @author: zhanglu
 * @create: 2019-12-01 22:17:00
 */
public class StaticProxy {

    public static void main(String[] args) {
        Subject subject = new ProxySubject();
        subject.request();
    }

}

interface Subject{

    void request();

}

class RealSubject implements Subject{

    @Override
    public void request() {
        System.out.println(" ---> request");
    }


}

class ProxySubject implements Subject{

    private RealSubject realSubject = null;

    @Override
    public void request() {

        preHandle();

        if(realSubject == null){
            realSubject = new RealSubject();
        }
        realSubject.request();

        endHandle();

    }

    private void preHandle() {
        System.out.println(" ---> preHandle");
    }

    private void endHandle() {
        System.out.println(" ---> endHandle");
    }

}